home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-02-27 | 1.2 KB | 44 lines | [TEXT/CWIE] |
- /* SK8 © 1997 Apple Computer, Inc.
- This code is protected under the current SK8 License
- See http://sk8.research.apple.com/ for more information
- Apple Research Laboratories
- */
-
- import java.util.Hashtable;
-
- class symbol {
- static Hashtable SymbolTable = new Hashtable();
- public String name;
-
- public symbol(String nameForSym) {
- //Check if a symbol with this name already exists
- String newName = nameForSym.toUpperCase();
- Object oldsym = SymbolTable.get(newName);
- if (oldsym != null)
- //should probably be throwing an exception here!
- sk8.sendtolog ("WARNING: REDEFINING AN EXISTING SYMBOL!" + newName);
-
- //here we take our new symbol, fill out it's name field and put it in our table.
- this.name = newName;
- SymbolTable.put(newName, this);
- }
-
- public String name() {
- return this.name;
- }
-
- //this is the standard function which will take a string and return
- //the corresponding symbol. If a symbol of that name does not already exist
- //it creates one.
- static public symbol getsymbol(String nameForSym) {
- symbol existingSym = (symbol)SymbolTable.get(nameForSym);
- if (existingSym == null)
- return new symbol(nameForSym);
- else
- return existingSym;
- }
-
- public String toString(){
- return name();
- }
- }